package com.fhyc.controller;

import com.fhyc.dao.SoInBaseVoltageDao;
import com.fhyc.dto.BusBarNaviDto;
import com.fhyc.entity.SoInBaseVoltage;
import com.fhyc.entity.SoInLoadType;
import com.fhyc.entity.SoInTeam;
import com.fhyc.service.SoInArAreaService;
import com.fhyc.service.SoInLoadTypeService;
import com.fhyc.service.SoInTeamService;
import com.fhyc.service.impl.BusBarServiceImpl;
import com.fhyc.vo.AreaInfoVo;
import com.fhyc.vo.ResponseResultVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 母线管理
 */
@Slf4j
@RestController
@RequestMapping("/api/fm/busBar")
@RequiredArgsConstructor
public class BaseInfoController {

    @Resource
    private BusBarServiceImpl busBarServiceImpl;

    @Resource
    private SoInArAreaService soInArAreaService;

    @Resource
    private SoInTeamService soInTeamService;

    @Resource
    private SoInLoadTypeService soInLoadTypeService;

    @Resource
    private SoInBaseVoltageDao soInBaseVoltageDao;

    /**
     * 获取母线（控制区、厂站）层级结构
     * name 模糊查询名称
     * voltageIds 电压等级id
     *
     * @return
     */
    @GetMapping("/getBusBarNaviTree")
    public ResponseResultVO<List<BusBarNaviDto>> getBusBarNaviTree(@RequestParam(value = "name", required = false) String name,
                                                                   @RequestParam(value = "voltageIds", required = false) List<Integer> voltageIds) {
        return new ResponseResultVO<>(busBarServiceImpl.getBusBarNaviTree(name, voltageIds));
    }


    @GetMapping("/getTeam")
    public ResponseResultVO<List<SoInTeam>> getTeamList() {
        return new ResponseResultVO<>(soInTeamService.getTeamList());
    }

    @GetMapping("/getArea")
    public ResponseResultVO<List<AreaInfoVo>> getAreaList() {
        List<AreaInfoVo> list = soInArAreaService.getAreaList();
        return new ResponseResultVO<>(list);
    }


    @GetMapping("/getLoadType")
    public ResponseResultVO<List<SoInLoadType>> getLoadType() {
        return new ResponseResultVO<>(soInLoadTypeService.getLoadTypeList());
    }

    @GetMapping("/getVoltage")
    public ResponseResultVO<List<SoInBaseVoltage>> getVoltage() {
        List<SoInBaseVoltage> list = soInBaseVoltageDao.selectList(null);
        for (SoInBaseVoltage soInBaseVoltage : list) {
            if (StringUtils.isNotEmpty(soInBaseVoltage.getUnit()) && null != soInBaseVoltage.getGrade()) {
                soInBaseVoltage.setVoltageName(soInBaseVoltage.getGrade() + soInBaseVoltage.getUnit());
            }
        }
        return new ResponseResultVO<>(list);
    }

}
